/**
 * 说明：
 * 创建人：pluto
 * 创建时间：2018/9/6
 */
var FactoryListCtrl = function ($scope, CustomerService, $uibModal, $log) {
    $scope.result = {};
    $scope.param = {pageNum: 1, pageSize: 10, authStatus: 2, userType: 2};

    var loadData = function (param) {
        CustomerService.list(param).then(function (res) {
            $scope.result = res;
        });
    };
    $scope.isFrozen = function (data) {
        var param = {id: data.id};
        var title = '确定冻结该用户吗？';
        if(data.isFrozen === 0){
            param.isFrozen = 1;
        }else{
            title = '确定解冻该用户吗？';
            param.isFrozen = 0;
        }
        layer.confirm(title, {btn: ['确定', '取消'], title: "提示"}, function () {
            CustomerService.isFrozen(param).then(function (res) {
                layer.msg('冻结成功', {icon: 1});
                loadData($scope.param);
            }).catch(function (err) {
                layer.msg(err.message, {icon: 2});
            })
        })

    };
    $scope.refreshCardImg = function (id) {
        CustomerService.refreshCardImg(id).then(function (res) {
            layer.msg('名片刷新成功', {icon: 1});
        }).catch(function (err) {
            layer.msg(err.message, {icon: 2});
        })
    }
    $scope.onPageChange = function () {
        $scope.param.pageNum = $scope.result.page.currentNo;
        loadData($scope.param);
    };
    $scope.$watch('$viewContentLoaded', function(){
        loadData($scope.param);
    });
};
angular.module('app.customer.factory.controller',[])
    .controller("FactoryListCtrl", FactoryListCtrl);
